package com.demo.phone;

import com.alibaba.fastjson.JSON;
import com.demo.phone.req.BaseRequest;
import com.demo.utils.HttpClientResult;
import com.demo.utils.HttpClientUtil;
import com.demo.utils.ParseMD5;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : YU.TAN
 * @date : 2021/10/26 17:45
 */
public class TestB {
    public static void main(String[] args) {
        RequestABO requestABO = new RequestABO();
        requestABO.setOrderId("861352066");

        Map<String, RequestABO> map = new HashMap(16);
        map.put("param", requestABO);

        String jsonString = JSON.toJSONString(requestABO);

        String s1 = JSON.toJSONString(map);
        System.out.println(s1);
        long time = System.currentTimeMillis() / 1000;
        BaseRequest build = BaseRequest.builder()
                .appKey("smart_marketing")
                .data(s1)
//                .timeStamp(String.valueOf(time))
                .timeStamp("1634353847")
                .param(jsonString)
                .appSecret("F4AA729C6F820C6742C9C57FC435B967")
                .build();

        String str = getStr(build);
        String sign = ParseMD5.parseStrToMd5U32(str);
        System.out.println(sign);

        String url = "https://scrm-smart-dev.gwm.com.cn/gwmSmartOutbound/sm/autohome/getAllCheckWords";

//        autohome : 汽车之家
//        yiche : 易车
        Map<String, String> params = new HashMap<>(16);
        params.put("appKey", build.getAppKey());
        params.put("timeStamp", build.getTimeStamp());
        params.put("sign", sign);
        params.put("data", build.getData());
        params.put("brandName", build.getBrandName());

        try {
            HttpClientResult result = HttpClientUtil.doPost(url, params);
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static String getStr(BaseRequest baseRequest) {
        String result = "%sappKey=%sparam=%stimestamp=%s%s";
//        String result="'%s'appKey='%s'param='%s'timestamp='%s''%s'";
        return String.format(result, baseRequest.getAppSecret(), baseRequest.getAppKey(), baseRequest.getParam(), baseRequest.getTimeStamp(), baseRequest.getAppSecret());
    }

}
